<?
$time = time();
$current_day = date('d', $time);
$current_month = date('m', $time);
$current_year = date('Y', $time);

//Khai báo biến khi thêm mới
$gs_action			= '';
$gs_redirect		= $gs_action;
$gs_errorMsg		= "";

//Lấy dữ liệu đề giữ nguyên trạng thái khi submit error
$ord_name			= getValue("ord_name", "str", "POST", "");
$ord_gender			= getValue("ord_gender", "int", "POST", 1);
$ord_address		= getValue("ord_address", "str", "POST", "");
$ord_email			= getValue("ord_email", "str", "POST", "");
$ord_phone			= getValue("ord_phone", "str", "POST", "");
$ord_mobile			= getValue("ord_mobile", "str", "POST", "");
$ord_fax			= getValue("ord_fax", "str", "POST", "");
$ord_otherinfo		= getValue("ord_otherinfo", "str", "POST", "");

$ord_sname			= getValue("ord_sname", "str", "POST", "");
$ord_sgender		= getValue("ord_sgender", "int", "POST", 1);
$ord_saddress		= getValue("ord_saddress", "str", "POST", "");
$ord_semail			= getValue("ord_semail", "str", "POST", "");
$ord_sphone			= getValue("ord_sphone", "str", "POST", "");
$ord_smobile		= getValue("ord_smobile", "str", "POST", "");
$ord_sfax			= getValue("ord_sfax", "str", "POST", "");
$ord_sotherinfo		= getValue("ord_sotherinfo", "str", "POST", "");

$ord_time			= getValue("ord_time", "str", "POST", "");
$ord_date			= getValue("ord_date", "int", "POST", $current_day);
$ord_month			= getValue("ord_month", "int", "POST", $current_month);
$ord_year			= getValue("ord_year", "int", "POST", $current_year);

$ord_payment_method			= getValue("ord_payment_method", "int", "POST", 1);
$ord_delivery_method			= getValue("ord_delivery_method", "int", "POST", 1);

//Get action variable for add new data
$action				= getValue("action", "str", "POST", "");
//Check $action for insert new data
if ($action == "execute")
{
	
	/*
	Call class form:
	1). Ten truong
	2). Ten form
	3). Kieu du lieu , 0 : string , 1 : kieu int, 2 : kieu email, 3 : kieu double, 4 : kieu hash password
	4). Noi luu giu data  0 : post, 1 : variable
	5). Gia tri mac dinh, neu require thi phai lon hon hoac bang default
	6). Du lieu nay co can thiet hay khong
	7). Loi dua ra man hinh
	8). Chi co duy nhat trong database
	9). Loi dua ra man hinh neu co duplicate
	*/
	$myform = new generate_form();
	//Add table insert data
	$myform->addTable('orders');
	$myform->add("ord_name", "ord_name", 0, 1, " ", 1, "Bạn chưa nhập tên người đặt hàng.", 0, "");
	$myform->add('ord_gender', 'ord_gender', 1, 1, 1, 0, '', 0, '');
	$myform->add("ord_address", "ord_address", 0, 1, " ", 1, "Bạn chưa nhập địa chỉ.", 0, "");
	$myform->add("ord_email", "ord_email", 0, 1, " ", 1, "Bạn chưa nhập email.", 0, "");
	$myform->add("ord_phone", "ord_phone", 0, 1, " ", 0, "", 0, "");
	$myform->add("ord_mobile", "ord_mobile", 0, 1, " ", 1, "Bạn chưa nhập di động.", 0, "");
	$myform->add("ord_fax", "ord_fax", 0, 1, " ", 0, "", 0, "");
	$myform->add("ord_otherinfo", "ord_otherinfo", 0, 1, " ", 0, "", 0, "");
	
	$myform->add("ord_sname", "ord_sname", 0, 1, " ", 1, "Bạn chưa nhập tên người nhận hàng.", 0, "");
	$myform->add('ord_sgender', 'ord_sgender', 1, 1, 1, 0, '', 0, '');
	$myform->add("ord_saddress", "ord_saddress", 0, 1, " ", 1, "Bạn chưa nhập địa chỉ.", 0, "");
	$myform->add("ord_semail", "ord_semail", 0, 1, " ", 1, "Bạn chưa nhập email.", 0, "");
	$myform->add("ord_sphone", "ord_sphone", 0, 1, " ", 0, "", 0, "");
	$myform->add("ord_smobile", "ord_smobile", 0, 1, " ", 1, "Bạn chưa nhập di động.", 0, "");
	$myform->add("ord_sfax", "ord_sfax", 0, 1, " ", 0, "", 0, "");
	$myform->add("ord_sotherinfo", "ord_sotherinfo", 0, 1, " ", 0, "", 0, "");
	
	$myform->add("ord_time", "ord_time", 0, 1, " ", 0, "", 0, "");
	$myform->add('ord_date', 'ord_date', 1, 1, 1, 0, '', 0, '');
	$myform->add('ord_month', 'ord_month', 1, 1, 1, 0, '', 0, '');
	$myform->add('ord_year', 'ord_year', 1, 1, 1, 0, '', 0, '');
	
	$myform->add('ord_payment_method', 'ord_payment_method', 1, 1, 1, 0, '', 0, '');
	$myform->add('ord_delivery_method', 'ord_delivery_method', 1, 1, 1, 0, '', 0, '');
	
	//Check form data
	$gs_errorMsg .= $myform->checkdata();
	
	if($gs_errorMsg == ""){
		
		//Insert to database
		$myform->removeHTML(0);
		$db_insert = new db_execute($myform->generate_insert_SQL());
		unset($db_insert);
		
		//Redirect after insert complate
		redirect($gs_redirect);
		
	}//End if($gs_errorMsg == "")
	unset($myform);
	
}//End if($action == "insert")
?>
<div class="navigate">
	<div class="L"></div>
    <div class="C">
    	<a class="home" href="<?=$con_root_path?>" lang="<?=$array_lang[$lang_id][0]?>"><?=tdt('Trang_chu')?></a>
        <img src="<?=$theme_imagepath?>navigate_icon.gif" /><span><?=$nData?></span>
	</div>
    <div class="R"></div>
</div>
<div id="cart" class="module_larger_title">
	<div class="L"></div>
	<div class="C"><a href="#cart" lang="<?=$array_lang[$lang_id][0];?>"><?=tdt('Don_hang_cua_ban');?></a></div>
	<div class="R"></div>
</div>
<div class="padding module_larger_border">
	<?
	if ($max > 0)
	{
	?>
	<form class="form" action="<?=$con_root_path;?>update_cart.php?return=<?=$return;?>" method="post">
		<table class="product_table_list" cellpadding="0" cellspacing="0">
		<tbody>
			<tr class="title">
				<td width="1%"><?=tdt('STT');?></td>
				<td width="1%"><?=tdt('Picture');?></td>
				<td><?=tdt('Ten_san_pham');?></td>
				<td width="1%"><?=tdt('Xoa');?></td>
				<td width="18%"><?=tdt('Don_gia');?></td>
				<td width="10%"><?=tdt('So_luong');?></td>
				<td width="20%"><?=tdt('Tong');?></td>
			</tr>
			<?
			$sum = 0;
			for ($i=0;$i<$max;$i++)
			{
				//var_dump($_SESSION['cart']);die();
				$db_listing = new db_query('SELECT cat_id,cat_name,products_multi.* FROM categories_multi,products_multi WHERE pro_id = ' . $_SESSION['cart'][$i]['pro_id'] . ' AND cat_id = pro_category_id LIMIT 1');
				$listing = mysql_fetch_array($db_listing->result);
				unset($db_listing);
				
				$detail_url = generate_detail_url('product', $listing['cat_id'], $listing['pro_id'], $listing['pro_name']);
			?>
			<tr class="list">
				<td class="No"><?=$i+1;?></td>
				<td align="center">
					<div class="picture_small">
						<a class="tooltip" href="<?=$detail_url;?>" target="_blank"><img maxwidth="25" maxheight="25" height="16" src="/products_pictures/small_<?=$listing['pro_picture'];?>" width="25"></a>
					</div>
				</td>
				<td>
					<a class="text_link" href="<?=$detail_url;?>" target="_blank"><?=$listing['pro_name'];?></a>
				</td>
				<td><input type="checkbox" value="1" name="delete<?=$i;?>"></td>
				<td class="price" align="right"><?=format_number($listing['pro_price']);?> <?=tdt('VND');?></td>
				<td align="center">
					<input type="text" class="form_control" name="quantity<?=$i;?>" value="<?=$_SESSION['cart'][$i]['pro_quantity'];?>" style="text-align:right; width:50px">
				</td>
				<td class="price" align="right">
				<?
				$temp = $listing['pro_price'] * $_SESSION['cart'][$i]['pro_quantity'];
				$sum = $sum + $temp;
				echo format_number($temp);?> <?=tdt('VND');?></td>
			</tr>
			<?
			}
			?>
			<tr>
				<td align="center" colspan="5">
					<!--<input type="button" class="form_button" value="<?=tdt('Thanh_toan');?>" onClick="window.location.href='<?=$con_root_path;?>payment.php?step=1'" />&nbsp;-->
					<input type="button" class="form_button" value="<?=tdt('Tiep_tuc_mua_hang');?>" onClick="window.location.href='<?=base64_decode($return);?>'" />&nbsp;
					<input type="submit" class="form_button" value="<?=tdt('Cap_nhat_gio_hang');?>">&nbsp;
					<div class="payment_recount_notice">* <?=tdt('Khi_ban_doi_so_luong_hay_click_vao_nut_cap_nhat_gio_hang_hang_de_he_thong_cap_nhat_lai_gio_hang');?></div>
				</td>
				<td align="right"><span style="font-weight:bold"><?=tdt('Thanh_tien');?> :</span></td>
				<td align="right" class="price"><?=format_number($sum);?> <?=tdt('VND');?></td>
			</tr>
		</tbody>
		</table>
	</form>
	<?
	}
	else
	{
	?>
	<div class="data_is_updating" lang="<?=$array_lang[$lang_id][0];?>"><?=tdt('Chua_co_san_pham_nao_trong_gio_hang_cua_ban');?></div>
	<?
	}
	?>
</div>
<div class="module_bottom"><div class="fl"></div><div class="fr"></div></div>
<div class="module_larger_title">
	<div class="L"></div>
	<div class="C"><a href="#"><?=tdt('Ban_hay_dien_thong_tin_ca_nhan_theo_mau_duoi_day');?></a></div>
	<div class="R"></div>
</div>
<div class="padding module_larger_border">
<?
$form = new form();
$form->create_form('payment', $con_root_path . 'payment.php?step=1', 'post', 'multipart/form-data','onsubmit="checkForm(this.name, arrCtrlPayment); return false;"');
$form->add_javascript($con_root_path . "js/library.php", "");
$form->create_table();
echo $form->text_note(tdt('Nhung_o_co_dau_sao_(*)_la_bat_buoc_phai_nhap'));
echo $form->errorMsg($gs_errorMsg);
?>
<tr class="text_title"><td colspan="2" id="ttndh">A - <?=tdt('Thong_tin_nguoi_dat_hang');?></td></tr>
<?=$form->text(tdt('Ten_nguoi_dat_hang'), "ord_name", "ord_name", $ord_name, tdt('Ten_nguoi_dat_hang'), 1, 250, "", 255, "", "", "");
echo $form->select(tdt('Gioi_tinh'), "ord_gender", "ord_gender", array(1=>'Nam',0=>'Nữ'), $ord_gender, tdt('Gioi_tinh'), 0, "", 1, 0, "", "");
echo $form->text(tdt('Dia_chi'), "ord_address", "ord_address", $ord_address, tdt('Dia_chi'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Email'), "ord_email", "ord_email", $ord_email, tdt('Email'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Dien_thoai_co_dinh'), "ord_phone", "ord_phone", $ord_phone, tdt('Dien_thoai_co_dinh'), 0, 250, "", 255, "", "", "");
echo $form->text(tdt('Dien_thoai_di_dong'), "ord_mobile", "ord_mobile", $ord_mobile, tdt('Dien_thoai_di_dong'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Fax'), "ord_fax", "ord_fax", $ord_fax, tdt('Fax'), 0, 250, "", 255, "", "", "");
echo $form->text(tdt('Ghi_chu'), "ord_otherinfo", "ord_otherinfo", $ord_otherinfo, tdt('Ghi_chu'), 0, 250, "", 255, "", "", "");
?>
<tr><td colspan="2"><div class="break_module_line"></div></td></tr>
<tr class="text_title"><td colspan="2" id="ttnnh">B - <?=tdt('Thong_tin_nguoi_nhan_hang');?></td></tr>
<tr>
    <td></td>
    <td class="form_text">
        <input type="checkbox" id="check_same" name="check_same" value="1" onclick="checkSame(this.checked)">
        <label class="text_link" for="check_same"><?=tdt('Thong_tin_nguoi_nhan_trung_voi_thong_tin_nguoi_dat_hang');?></label>
    </td>
</tr>
<?=$form->text(tdt('Ten_nguoi_nhan_hang'), "ord_sname", "ord_sname", $ord_sname, tdt('Ten_nguoi_nhan_hang'), 1, 250, "", 255, "", "", "");
echo $form->select(tdt('Gioi_tinh'), "ord_sgender", "ord_sgender", array(1=>'Nam',0=>'Nữ'), $ord_sgender, tdt('Gioi_tinh'), 0, "", 1, 0, "", "");
echo $form->text(tdt('Dia_chi'), "ord_saddress", "ord_saddress", $ord_saddress, tdt('Dia_chi'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Email'), "ord_semail", "ord_semail", $ord_semail, tdt('Email'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Dien_thoai_co_dinh'), "ord_sphone", "ord_sphone", $ord_sphone, tdt('Dien_thoai_co_dinh'), 0, 250, "", 255, "", "", "");
echo $form->text(tdt('Dien_thoai_di_dong'), "ord_smobile", "ord_smobile", $ord_smobile, tdt('Dien_thoai_di_dong'), 1, 250, "", 255, "", "", "");
echo $form->text(tdt('Fax'), "ord_sfax", "ord_sfax", $ord_sfax, tdt('Fax'), 0, 250, "", 255, "", "", "");
echo $form->text(tdt('Ghi_chu'), "ord_sotherinfo", "ord_sotherinfo", $ord_sotherinfo, tdt('Ghi_chu'), 0, 250, "", 255, "", "", "");
?>
<tr class="text_title"><td colspan="2" id="ttndh">C - <?=tdt('Phuong_thuc_thanh_toan');?></td></tr>
<?=$form->select(tdt('Phuong_thuc_thanh_toan'), "ord_payment_method", "ord_payment_method", array(1 => tdt('Thanh_toan_bang_tien_mat')), $ord_payment_method, tdt('Phuong_thuc_thanh_toan'), 0, "", 1, 0, "", "");
?>
<tr class="text_title"><td colspan="2" id="ttndh">D - <?=tdt('Hinh_thuc_van_chuyen');?></td></tr>
<?=$form->select(tdt('Hinh_thuc_van_chuyen'), "ord_delivery_method", "ord_delivery_method", array(1 => tdt('Den_dia_chi_nguoi_nhan')), $ord_delivery_method, tdt('Hinh_thuc_van_chuyen'), 0, "", 1, 0, "", "");
?>
<tr>
    <td class="form_name"><?=tdt('Thoi_gian_mong_muon_nhan_hang');?> :</td>
    <td class="form_text">
        <input type="text" class="form_control" id="ord_time" name="ord_time" value="<?=$ord_time;?>" maxlength="30" style="width:70px">
        <select class="form_control" id="ord_date" name="ord_date">
		<? for ($i=1;$i<=31;$i++) {?>
        	<option value="<?=$i?>"<?=($i == $current_day)?' checked="checked"':''?>><?=$i?></option>
        <? }?>
        </select>
        <select class="form_control" id="ord_month" name="ord_month">
        <? for ($i=1;$i<=12;$i++) {?>
        	<option value="<?=$i?>"<?=($i == $current_month)?' checked="checked"':''?>><?=$i?></option>
        <? }?>
        </select>
        <select class="form_control" id="ord_year" name="ord_year">
        <? for ($i=2011;$i<=2021;$i++) {?>
        	<option value="<?=$i?>"<?=($i == $current_year)?' checked="checked"':''?>><?=$i?></option>
        <? }?>
        </select>
        &nbsp;<i>(<?=tdt('Gio');?> : <?=tdt('phut');?> - <?=tdt('Ngay');?> / <?=tdt('Thang');?> / <?=tdt('Nam');?>)</i>
    </td>
</tr>
<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", tdt('Gui_di') . $form->ec . tdt('Lam_lai'), tdt('Gui_di') . $form->ec . tdt('Lam_lai'), '' . $form->ec . '', "");
echo $form->hidden("action", "action", "execute", "");
$form->close_table();
$form->close_form();
unset($form);
?>
</div>
<script type="text/javascript">
function checkSame(c){
var arrOb= Array("name", "gender", "address", "email", "phone", "mobile", "fax", "otherinfo");
for(i=0; i<arrOb.length; i++){
value= (c ? document.getElementById("ord_" + arrOb[i]).value : "");
document.getElementById("ord_s" + arrOb[i]).value = value;
}
}
</script>
<div class="module_bottom"><div class="fl"></div><div class="fr"></div></div>